package com.carrent.bus.controller;

import com.carrent.bus.domain.Rent;
import com.carrent.bus.service.CheckService;
import com.carrent.bus.service.RentService;
import com.carrent.bus.vo.CheckVo;
import com.carrent.bus.vo.RentVo;
import com.carrent.sys.utils.DataGridView;
import com.carrent.sys.utils.ResultObj;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.Map;

/**
 * 检查单控制器
 *
 */
@RestController
@Api(tags = "检查单控制器")
@RequestMapping("check")
public class CheckController {
    @Autowired
    private RentService rentService;
    @Autowired
    private CheckService checkService;

    /******************汽车入库开始********************/

    /**
     * 检查出租单号是否存在
     */
    @RequestMapping("checkRentIdtIsExit")
    public Rent checkRentIdtIsExit(String rentid){
        return rentService.queryRentByRentid(rentid);
    }

    /**
     * 初始化表单数据initCheckCarForm
     */
    @RequestMapping("initCheckCarForm")
    public Map<String,Object> initCheckCarForm(String rentid){
        return checkService.initCheckCarForm(rentid);
    }

    /**
     * 保存--增加检查单
     */
    @RequestMapping("saveCheckOrder")
    public ResultObj saveCheckOrder(CheckVo checkVo){
        try{
            checkVo.setCreatetime(new Date());
            checkService.saveCheckOrder(checkVo);
            return  ResultObj.ADD_SUCCESS;
        }catch (Exception e){
            return ResultObj.ADD_ERROR;
        }
    }
/******************汽车入库结束********************/

/******************检查单管理开始********************/

    /**
     * 查询所有检查单
     */
    @RequestMapping("loadAllCheck")
    public DataGridView loadAllCheck(CheckVo checkVo){
        DataGridView dataGridView = checkService.loadAllCheck(checkVo);
        return dataGridView;
    }

    /**
     * 修改检查单
     */
    @RequestMapping("updateCheckOrder")
    public ResultObj updateCheckOrder(CheckVo checkVo){
        try{
            checkService.updateCheckOrder(checkVo);
            return ResultObj.ADD_SUCCESS;
        }catch (Exception e){
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 删除检查单
     */
    @RequestMapping("deleteCheckOrder")
    public ResultObj deleteCheckOrder(CheckVo checkVo){
        try{
            checkService.deleteCheckOrder(checkVo);
            return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            return ResultObj.DELETE_ERROR;
        }
    }
}
